package class21To30;

import java.io.*;

public class MergeSort {

    public static final int MAX_N = 10005;

    private static int[] arr = new int[MAX_N];

    private static int[] help = new int[MAX_N];

    private static int n;


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int) in.nval;
        for (int i = 0; i < n; i++) {
            in.nextToken();
            arr[i] = (int) in.nval;
        }
        mergeSortRecursion(0, n - 1);
        mergeSortIteration();
        for (int i = 0; i < n - 1; i++) {
            out.print(arr[i] + " ");
        }
        out.println(arr[n - 1]);
        out.flush();
        out.close();
        br.close();
    }

    private static void mergeSortIteration() {
        for (int l, m, r, step = 1; step < n; step *= 2) {
            l = 0;
            while (l < n) {
                // 规定左边的右边界
                m = l + step - 1;
                // 特殊处理没有右边的情况
                if (m + 1 >= n) {
                    break;
                }
                // 规定右边的右边界
                r = Math.min(l + (step * 2) - 1, n - 1);
                merge(l, m, r);
                l = r + 1;
            }
        }
    }

    public static void mergeSortRecursion(int l, int r) {
        if (l == r)
            return;
        int m = l + ((r - l) >> 1);
        mergeSortRecursion(l, m);
        mergeSortRecursion(m + 1, r);
        merge(l, m, r);
    }

    private static void merge(int l, int m, int r) {
        int i = l;
        int left = l;
        int right = m + 1;
        while (left <= m && right <= r) {
            if (arr[left] <= arr[right])
                help[i++] = arr[left++];
            else
                help[i++] = arr[right++];
        }
        while (left <= m)
            help[i++] = arr[left++];
        while (right <= r)
            help[i++] = arr[right++];
        for (int j = l; j <= r; j++)
            arr[j] = help[j];
    }
}
